package com.b8a3.themedemo;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.NumberPicker;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

import java.util.Arrays;
import java.util.List;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    private TextView mTextMessage;
    private Button bt_c_activity;
    private Button bt_c_appcompatactivity;
    private Spinner spinner;
    private int themeId = android.R.style.Theme;
    private String themeName = "Theme";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setTheme(R.style.AppTheme);

        setContentView(R.layout.activity_main);
        mTextMessage = (TextView) findViewById(R.id.message);
        bt_c_activity = findViewById(R.id.bt_c_activity);
        bt_c_appcompatactivity = findViewById(R.id.bt_c_appcompatactivity);
        bt_c_activity.setOnClickListener(this);
        bt_c_appcompatactivity.setOnClickListener(this);

        spinner = findViewById(R.id.spinner);
        List<String> list = Arrays.asList(ThemeModel.themeNames);
        ArrayAdapter<String> minAdapter = new ArrayAdapter<String>(this, R.layout.support_simple_spinner_dropdown_item, list);
        this.spinner.setAdapter(minAdapter);
    }

    @Override
    public void onClick(View v) {
        themeId = ThemeModel.themeIds[spinner.getSelectedItemPosition()];
        switch (v.getId()) {
            case R.id.bt_c_activity:
                Intent intent = new Intent();
                intent.setClass(this, ThemeShowActivity.class);
//                intent.putExtra(ThemeShowActivity.THEME_KEY, R.style.theme_appCompat);
//                intent.putExtra(ThemeShowActivity.THEME_KEY, R.style.theme_material);
                intent.putExtra(ThemeModel.THEME_KEY, themeId);
                intent.putExtra(ThemeModel.ACTIVITY_TAP_KEY, "Activity");
                startActivity(intent);
                break;
            case R.id.bt_c_appcompatactivity:
                if (spinner.getSelectedItemPosition() + 24 < ThemeModel.themeIds.length) {
                    Toast.makeText(this, "AppcompatActivity 使用 AppCompatTheme", Toast.LENGTH_SHORT).show();
                    break;
                }
                Intent intent1 = new Intent();
                intent1.setClass(this, ThemeAppCompatActivity.class);
//                intent.putExtra(ThemeShowActivity.THEME_KEY, R.style.theme_appCompat);
//                intent.putExtra(ThemeShowActivity.THEME_KEY, R.style.theme_material);
                intent1.putExtra(ThemeModel.THEME_KEY, themeId);
                intent1.putExtra(ThemeModel.ACTIVITY_TAP_KEY, "AppCompatActivity");
                startActivity(intent1);
                break;
        }
    }
}
